﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PIMS
{
    public partial class FormSuppleInfo : Form
    {
        public FormSuppleInfo()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.txtBatch.Text))
            {
                MessageBox.Show("修改后的外部批次不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (String.IsNullOrEmpty(this.txtListNum.Text))
            {
                MessageBox.Show("修改后的小批次不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (String.IsNullOrEmpty(this.txtBatchRule.Text))
            {
                MessageBox.Show("修改后的分批规则不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (String.IsNullOrEmpty(this.cbxPalRule.Text))
            {
                MessageBox.Show("修改后的码垛规格不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (this.txtBatch.Text.Length != 8 && this.txtBatch.Text.Length != 12)
            {
                MessageBox.Show("修改后的外部批次长度异常！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (this.txtListNum.Text.Length != 4)
            {
                MessageBox.Show("修改后的小批次长度异常！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (!IsDouble(this.txtBatchRule.Text))
            {
                MessageBox.Show("分批规则输入值无法解析！请输入正浮点数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (!IsDouble(this.cbxPalRule.Text))
            {
                MessageBox.Show("码垛规格输入值无法解析！请输入正浮点数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void FormSuppleInfo_Load(object sender, EventArgs e)
        {
            this.txtBatch.Enabled = !Common.bSendPLC;
            this.txtListNum.Enabled = !Common.bSendPLC;
            this.txtBatchRule.Enabled = !Common.bSendPLC;
            this.cbxPalRule.Enabled = !Common.bSendPLC;
            this.txtPecialInfo.Enabled = !Common.bSendPLC;
            this.txtReclaimLogo.Enabled = !Common.bSendPLC;
        }

        //判断字符串是否可以转化为正浮点数
        public static bool IsDouble(string inString)
        {
            Regex regex = new Regex("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");
            return regex.IsMatch(inString.Trim());
        }
    }
}
